import React from 'react'
//导入 store 对象
import store from '../../redux/store';
//导入 action creator
import { addAction, subAction, asyncAddAction } from '../../redux/reducers/CountReducer'
import { increAction } from '../../redux/reducers/ZanReducer';
export default function ReduxCom() {
  //这里其实可以进行解构赋值
  // let {zan, count} = store.getState()
  return (
    <div>
      <h2>{store.getState().count}</h2>
      <button onClick={() => {
        //更新状态
        store.dispatch(addAction(1));
        //查看最新状态
        // console.log(store.getState());
      }}>新增</button>
      <button onClick={() => {
        store.dispatch(subAction(10));
      }}>减少</button>
      <button onClick={() => {
        //定时器
        store.dispatch(asyncAddAction(5));
      }}>1 秒之后新增 1</button>

      <hr />
      <h2>点赞数: {store.getState().zan}</h2>
      <button onClick={() => {
        store.dispatch(increAction(1));
      }}>点赞</button>

    </div>
  )
}
